package tw.asap.plus.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import tw.asap.plus.R;
import tw.asap.plus.ui.AsapBaseActivity;
import tw.asap.plus.ui.custom.AppBar;
import tw.asap.plus.utils.Toaster;

/**
 * Created by Yax.
 * Date: 15/12/5
 * Time: 下午2:32
 * Description:
 */
public class MemoActivity extends AsapBaseActivity {

    @InjectView(R.id.appbar)
    AppBar appbar;
    @InjectView(R.id.memo)
    EditText memo;
    @InjectView(R.id.bt_submit)
    Button btSubmit;
    String memoStr;
    private static final int MAX_MEMO_LENGTH = 25;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_memo);
        ButterKnife.inject(this);
        memoStr = getIntent().getStringExtra("MEMO");
        if(!TextUtils.isEmpty(memoStr)){
            memo.setText(memoStr);
        }
    }


    @OnClick(R.id.bt_submit)
    protected void submit() {
        String memoInfo = memo.getText().toString();
        if(!TextUtils.isEmpty(memoInfo) && memoInfo.length()>MAX_MEMO_LENGTH){
            Toaster.s(this,getString(R.string.memo_too_long));
            return;
        }


        Intent intent = new Intent();
        intent.putExtra("MEMO", memoInfo);
        setResult(RESULT_OK, intent);
        finish();
    }
}
